package epidemic;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;


public class EpiUtils {
	public static void drawArrow(Graphics g, Vec from, Vec to, int size) {
		g.drawLine((int) from.x, (int) from.y, (int) to.x, (int) to.y);
		
		Vec line = to.sub(from);
		Vec left = to.add(line.normal().unit().mul(size).sub(line.unit().mul(size)));
		Vec right = to.add(line.normal().unit().mul(-size).sub(line.unit().mul(size)));
		
		g.drawLine((int) to.x, (int) to.y, (int) left.x, (int) left.y);
		g.drawLine((int) to.x, (int) to.y, (int) right.x, (int) right.y);
	}
	
	public static void drawShadedString(Graphics g, String str, Color text, Color shade, int x, int y) {
		g.setColor(shade);
		g.drawString(str, x+1, y+1);
		g.setColor(text);
		g.drawString(str, x, y);
	}
	
	public static void drawStringWithBackground(Graphics g, String str, Color text, Color bg, int x, int y) {
		// Determine where the text is rendered
		FontMetrics fm = g.getFontMetrics(g.getFont());
		Rectangle2D bounds = fm.getStringBounds(str, g);
		
		// Paint a colored background
		g.setColor(bg);
		g.fillRect(x + (int) bounds.getX(), y + (int) bounds.getY(), (int) bounds.getWidth(), (int) bounds.getHeight());
		
		// Paint the text on top the background
		g.setColor(text);
		g.drawString(str, x, y);
	}
}
